package com.llgz.hotelmanageapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.llgz.hotelmanageapi.mapper.CheckinInfoMapper;
import com.llgz.hotelmanageapi.mapper.CheckoutInfoMapper;
import com.llgz.hotelmanageapi.mapper.IndexMapper;
import com.llgz.hotelmanageapi.pojo.DO.CheckoutInfo;
import com.llgz.hotelmanageapi.service.IndexServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LinHj
 * @date 2021/7/27 15:44
 **/
@Service
public class IndexServiceImpl implements IndexServer {
    @Autowired
    IndexMapper indexMapper;

    @Override
    public Map<String, Object> getData() {
        List<Map<String, Object>> showData = indexMapper.getShowData();
        HashMap<String, Object> map = new HashMap<>();
        map.put("orderNum",showData.get(0).get("a"));
        map.put("checkInPeoples",showData.get(1).get("a"));
        if(showData.get(2) == null){
            map.put("yesterdayIncome",0);
        }else {
            map.put("yesterdayIncome",showData.get(2).get("a"));
        }
        map.put("memberNum",showData.get(3).get("a"));
        return map;
    }
    @Override
    public List<Double> getLastWeekIncome(){
        List<Map<String, Object>> lastWeekIncome = indexMapper.getLastWeekIncome();
        ArrayList<Double> incomes = new ArrayList<>();
        for (Map<String,Object> map:lastWeekIncome){
            if (map == null) {
                incomes.add(0.0);
            }else {
                incomes.add((double)map.get("a"));
            }
        }
        return incomes;
    }

    @Override
    public List<Double> getLastWeekAccommodationExpenses() {
        List<Map<String, Object>> lastWeekExpenses = indexMapper.getLastWeekAccommodationExpenses();
        ArrayList<Double> expenses = new ArrayList<>();
        for (Map<String,Object> map:lastWeekExpenses){
            if (map == null) {
                expenses.add(0.0);
            }else {
                expenses.add((double)map.get("a"));
            }
        }
        return expenses;
    }

}
